/*首页 */




EMui.vmIndex=(function(){
    var views={};

    //热门新闻  --包含  幻灯片 与 新闻列表两个视图;
    views.focus=[
        new LeafView({
            id:"#newsHdp",
            state:{isAddSlider:false,isShow:true},
            param:{
                url:EMui.urls.domain+EMui.urls.newsHdp,
                data:{ _start:0, _limit:4 }
            },
            vm:new Vue({
                el:$("#newsHdp > .swiper-wrapper")[0] ,
                data:{list:[]},
                watch:{
                    'list':function () {
                        var me=views.focus[0];
                        if (!me.state.isAddSlider) {
                            new Swiper('.swiper-container', {
                                pagination: '.swiper-pagination',
                                paginationClickable: true,
                                loop: true
                            });
                            me.state.isAddSlider = true;
                        }
                    }
                }
            }),
            isLoadMore:false
        }),

        new LeafView({
            id:"#newsFocus",
            state:{isShow:true},
            param:{
                url:EMui.urls.domain+EMui.urls.newsFocus,
                data:{ _start:0, _limit:10 }
            }
        })
    ];

    //转会名称
    views.transfer=[
        new LeafView({
            id:"#newsTransfer",
            state:{isShow:false},
            elBox:$("#newsTransfer>ul")[0],
            param:{
                url:EMui.urls.domain+EMui.urls.newsTransfer,
                data:{ _start:0, _limit:5 }
            },
            dataAdd:function(data){
                function getText(){
                    var en={"now":"Now", "past":"Pasted", "join":"Joined"},
                        zh={"now":"现在", "past":"过去", "join":"转入"},
                        tw={"now":"現在", "past":"過去", "join":"轉入"};
                    var curLang=EMui.storageService.get("curLang");
                    var ret=en;
                    if(curLang==='zh-CN'){
                        ret=zh;
                    }else if(curLang==='zh-TW'){
                        ret=tw;
                    }
                    return ret;
                }
                var curText=getText();
                $.each(data,function(index,item){
                    item.now=curText.now;
                    item.past=curText.past;
                    item.join=curText.join;
                });
                return data;
            }
        })
    ];

    //头条热话
    views.headlines=[
        new LeafView({
            id:"#newsHeadlines",
            state:{isShow:false},
            elBox:$("#newsHeadlines>ul")[0],
            param:{
                url:EMui.urls.domain+EMui.urls.newsHeadlines,
                data:{ _start:0, _limit:15 }
            }
        })
    ];



    //切换标签
    var tab=$("#newsType"),lis=$("li",tab),viewName,curView=null;
    lis.on("changetab",function(){
        viewName=$(this).data("view");
        curView=views[viewName];
        for(var arr in views){
            if(curView==views[arr]){
                $.each(views[arr],function(n,view){
                    view.state.isShow=true;
                    if(view.vm.list.length<=0){
                        view.fillData();
                    }
                });
            }else{
                $.each(views[arr],function(n,view){
                    view.state.isShow=false;
                });
            }

        }
    });


    return{
        init:function(){
           for(var arr in views){
               $.each(views[arr],function(n,view){
                   if(view.state.isShow){
                       view.fillData();
                   }
               });
           }
        },
        reloadData:function(){
            for(var arr in views){
                $.each(views[arr],function(n,view){
                    view.param.data={_start:view.oldParamPage._start,_limit:view.oldParamPage._limit};
                    view.state.isNoneData=false;
                    view.vm.list=[];
                    if(view.state.isShow){
                        if(view.isLoadMore){view.offLoadMore();}
                        view.fillData();
                    }
                });
            }
        }
    }
})();



